package com.dong.service.impl;

import com.dong.dao.UserMapper;
import com.dong.entitys.User;
import com.dong.service.UserService;
import com.dong.tools.DBTools;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements UserService {
    @Override
    public Integer addUser(User user) {
        SqlSession session = DBTools.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        Integer integer = mapper.addUser(user);
        session.commit();
        session.close();
        return integer;
    }

    @Override
    public List<User> selectAllUser() {
        SqlSession session = DBTools.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> users = mapper.selectAllUser();
        session.commit();
        session.close();
        return users;
    }

    @Override
    public void updateUserStatus(User user) {
        SqlSession session = DBTools.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        mapper.updateUserStatus(user);
        session.commit();
        session.close();

    }

    @Override
    public User selectUserByNP(String user_name, String user_pwd) {
        SqlSession session = DBTools.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = mapper.selectUserByNP(user_name, user_pwd);
        session.commit();
        session.close();
        return user;
    }
}
